package com.cari.oa.domain;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.validator.constraints.Length;

/**
 * 部门实体
* Title: SysDeptEntity
* Description:
* Company: cari 
* @author    hjx 
* @date       2013-1-21
 */
@Entity
@Table(name = "t_sys_dept")
public class SysDeptEntity implements Serializable{
	
	private static final long serialVersionUID = 1L;

	/**
     * id
     */
    @Id
    @Length(max = 32)
    @GeneratedValue(generator = "system-uuid")
    @GenericGenerator(name = "system-uuid", strategy = "uuid")
	private String id;           
    
    /**
     * 编号
     */
    @NotNull(message = "部门编号不能为空")
    @Column(name = "DEPT_NO")
    @Length( min=2  ,max = 50, message = "部门编号长度要在2-50个字符")
	private String deptNo;  
    
    /**
     * 名称
     */
    @Column(name = "DEPT_NAME")
    @NotNull(message = "部门名称不能为空")
    @Length( max = 50, message = "部门名称长度要小于50个字符")
	private String deptName;    
	
	/**
	 * 父部门Id
	 */
    @Column(name = "PARENT_NO")
	private String pNo;  
	
    /**
	 * 地址
	 */
    @Column(name = "ADDRESS")
    @Length(max = 200, message = "部门地址长度要小于200个字符")
	private String address;
    

    /**
	 * 地区
	 */
    @Column(name = "AREA")
    @Length(max = 200, message = "部门地区长度要小于200个字符")
	private String area;
    
    /**
     * 描述
     */
    @Column(name = "describe")
    @Length(max = 500, message = "描述要小于500个字符")
    private String describe;

    /**
     * 存储子部门
     */
    @Transient
    private List<SysDeptEntity> childDept;
    
    /**
     * 父亲节点的名称
     */
    @Transient
    private String pDeptName; 
    
    @Transient
    private String isChild;
    
	public String toTreeString()
    {
    	StringBuffer sb = new StringBuffer();
    	if(childDept == null || childDept.size() == 0)  //顶级节点下没有子节点
    	{
    		sb.append("<li rel='"+this.deptNo+"'> "+this.deptName+" </li>");
    	}else                                      
    	{
    		sb.append("<li rel='"+this.deptNo+"'> "+this.deptName);
    		sb.append("<ul>");
    		for(SysDeptEntity child : childDept)
    		{
    			sb.append(child.toTreeString());    		
    		}
    		sb.append("</ul></li>");
    	}
    	return sb.toString();
    }

	public String getId() {
		return id;
	}


	public void setId(String id) {
		this.id = id;
	}


	public String getDeptNo() {
		return deptNo;
	}


	public void setDeptNo(String deptNo) {
		this.deptNo = deptNo;
	}


	public String getDeptName() {
		return deptName;
	}


	public void setDeptName(String deptName) {
		this.deptName = deptName;
	}


	public String getAddress() {
		return address;
	}


	public void setAddress(String address) {
		this.address = address;
	}


	public String getArea() {
		return area;
	}


	public void setArea(String area) {
		this.area = area;
	}


	public String getpNo() {
		return pNo;
	}


	public void setpNo(String pNo) {
		this.pNo = pNo;
	}


	public String getDescribe() {
		return describe;
	}


	public void setDescribe(String describe) {
		this.describe = describe;
	}
	
    public List<SysDeptEntity> getChildDept() {
		return childDept;
	}

	public void setChildDept(List<SysDeptEntity> childDept) {
		this.childDept = childDept;
	}

	public String getpDeptName() {
		return pDeptName;
	}

	public void setpDeptName(String pDeptName) {
		this.pDeptName = pDeptName;
	}

	public String getIsChild() {
		return isChild;
	}

	public void setIsChild(String isChild) {
		this.isChild = isChild;
	}
}
